package javafx179labs.melnik.lab2;

import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.ext.swing.SwingTextField;
import javafx.ext.swing.SwingButton;
import javafx.scene.input.MouseEvent;
import javafx.scene.Group;
import javafx.scene.text.Text;


/**
 * @author elen
 */

var texti: Group[] = [];
def x = 100;
def y = 30;

var predpisanie : Text = Text{
     layoutX: 30
     layoutY: 10
     content: "Введите название книги, которую вы прочитали"
}

var textik: SwingTextField = SwingTextField {
columns: 25
    layoutX: 17
    layoutY: 15
editable: true
    }

  var dobavka: SwingButton = SwingButton {
        text: "Добавить"
        width: x
        height: y+5
        layoutX: 410
        onMouseClicked: function(e: MouseEvent) {
                insert izmenit(textik.text) into texti;
                textik.text=""
                }

    }

function wagi (seq: Group[]) {
        var inc = 0; for (e in seq) {
        e.translateY = inc; inc += 30;
        }
        return seq;
        }

function izmenit(str: String) {
    var textik: SwingTextField = SwingTextField {
        columns: 30
        text: str
        editable: false
    }

    var knopka1: SwingButton = SwingButton {
        text: "Изменить"
        width: x
        height: y
        layoutX: 350
        onMouseClicked: function(e: MouseEvent) {
                textik.editable = not textik.editable;
                }
    }


    var knopka2: SwingButton = SwingButton {
        text: "Удалить"
        width: x
        height:y
        layoutX: 465
        onMouseClicked: function(e: MouseEvent) {
                delete name from texti;
                }
    }

      var name: Group = Group {
        content: [textik, knopka1, knopka2]
    }
return name
}


insert izmenit("Евгений Онегин") into texti;
insert izmenit("Мастер и Маргарита") into texti;
insert izmenit ("Темные аллеи") into texti;
insert izmenit ("Братья Карамазовы") into texti;

Stage {
       title: "Список прочитанных книг"
       scene: Scene {
       width: 700
       height: 500
        content: [
                textik,
                dobavka,
                predpisanie,
                Group {
                    translateY: 45
                    content: bind [wagi(texti)]
                                    }
        ]
    }
}